package com.hunan.api.catv.action.subscribe;

import com.hunan.api.catv.action.BaseAction;
import com.hunan.api.catv.annotation.MemberAuth;
import com.hunan.api.catv.common.Api;
import com.hunan.api.catv.entity.Result;
import com.hunan.api.catv.service.biz.subscribe.SubscribeBiz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;


@RestController
@RequestMapping(Api.subscribe)
@Validated
public class SubscribeAction extends BaseAction {

    @Autowired
    SubscribeBiz subscribeBiz;

    @MemberAuth
    @PostMapping("/submit")
    public Result submit(HttpServletRequest request, Integer flag, Integer contentType, String content) {
        if (ObjectUtils.isEmpty(flag)) {
            return buildRequire("flag require");
        }
        if (ObjectUtils.isEmpty(contentType)) {
            return buildRequire("contentType require");
        }
        if (ObjectUtils.isEmpty(content)) {
            return buildRequire("contentId require");
        }
        return buildResult(subscribeBiz.submit(flag, getMemberId(request), contentType, content));
    }

    @MemberAuth
    @GetMapping("/query")
    public Result query(HttpServletRequest request, Integer contentType, String content) {
        return buildOK(subscribeBiz.query(getMemberId(request), contentType, content), "");
    }

    @MemberAuth
    @GetMapping("/queryAllSubscribe")
    public Result queryAllSubscribe(HttpServletRequest request, Integer contentType, String content) {
        return buildOK(subscribeBiz.queryAllSubscribe(getMemberId(request), contentType, content), "");
    }

    @MemberAuth
    @GetMapping("/list")
    public Result list(HttpServletRequest request, Integer contentType) {
        return buildOK(subscribeBiz.list(getMemberId(request), contentType), "");
    }
}
